﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 学生选课及成绩查询管理系统
{
    public partial class StudentLogin : Form
    {
        public StudentLogin()
        {
            InitializeComponent();
        }

        User user;

        internal User User
        {
            get { return user; }
            set { user = value; }
        }

        internal void Welcome(User user)
        {
            toolStripStatusLabel1.Text = "欢迎用户:" + user.Userid + "_" + user.Username;
        }

        private void StudentLogin_Load(object sender, EventArgs e)
        {
            toolStripStatusLabel3.Text = DateTime.Now.ToString();
        }

        private void StudentLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("是否要退出程序", "关闭提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                e.Cancel = true;
            }
            else
            {
                Dispose();
                Application.Exit();
            }
        }

        private void toolStripStatusLabel3_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel3.Text = DateTime.Now.ToString();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabel3.Text = DateTime.Now.ToString();
        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {

        }

        private void 修改个人密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                UpdatePwd up = new UpdatePwd();
                up.User = user;
                up.MdiParent = this;
                up.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }

        private void 注销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1(user);
            MessageBox.Show("注销成功");
            f1.Show();
            this.Dispose();
        }

        private void 我的成绩单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                showStudentGradeInfo ssgi = new showStudentGradeInfo();
                ssgi.User = user;
                ssgi.MdiParent = this;
                ssgi.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }

        private void 选课ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 查看课程ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                showStudentPersonalCourseTableInfo sspcti = new showStudentPersonalCourseTableInfo();
                sspcti.User = user;
                sspcti.MdiParent = this;
                sspcti.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }
            private static string startTime = DateTime.Now.ToString("yyyy-04-06");
            private static string overTime = DateTime.Now.ToString("yyyy-04-20");
            DateTime startTime1 = Convert.ToDateTime(startTime);
            DateTime overTim1 = Convert.ToDateTime(overTime);

        private void 选修课选修ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            if (this.MdiChildren.Count() < 1)
            {
                string sql = "select count(*) from student where stustate=0 and stuno="+user.Username;
                object res=DBAccess.GetOne(sql);
                if ((int)res!=0)
                {
                    MessageBox.Show("您已毕业或不在学校就读!");
                    return;
                }
                else
                {
                    string nowsday = DateTime.Now.ToString("yyyy-MM-dd");
                    DateTime nowsday1 = Convert.ToDateTime(nowsday);
                    if (DateTime.Compare(nowsday1, startTime1) > 0 && DateTime.Compare(nowsday1, overTim1) < 0)
                    {
                        MessageBox.Show("选课时间在4月的6号到20号，请还没选课的同学抓紧选课！");
                        optionalCourseToChooseInfo oitci = new optionalCourseToChooseInfo();
                        oitci.User = user;
                        oitci.MdiParent = this;
                        oitci.Show();
                    }
                    else
                    {
                        MessageBox.Show("您已过了选课时间段,该界面已关闭！");
                        return;
                    }
 
                }
                
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }

        private void 班级信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() < 1)
            {
                showStudentClassSituationInfo sscsi = new showStudentClassSituationInfo();
                sscsi.User = user;
                sscsi.MdiParent = this;
                sscsi.Show();
            }
            else
            {
                MessageBox.Show("只能打开一个Mdi子窗体");
            }
        }


    }
}
